package com.example.test.controller;


import com.example.test.bean.BraendType;
import com.example.test.bean.GoodType;
import com.example.test.common.model.PageModel;
import com.example.test.common.model.R;
import com.example.test.service.BraendTypeService;
import com.example.test.service.GoodTypeService;

import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 基础分类表 前端控制器
 * </p>
 *
 * @author dz
 * @since 2022-04-10
 */
@CrossOrigin
@RestController
@RequestMapping("/good-type")
public class GoodTypeController {


    @Resource
    private GoodTypeService goodTypeService;

    @ApiOperation(value = "根据keyword分页查询")
    @GetMapping("/searchTypes")
    public R pageList(String keyword, PageModel pageModel) {
        return goodTypeService.getTypeByKeyword(keyword,pageModel);
    }

    @ApiOperation(value = "根据id分页查询")
    @GetMapping("/getType")
    public R page( Long typeId) {
        return goodTypeService.getTypeById(typeId);
    }

    @ApiOperation(value = "添加")
    @PostMapping(value = "/insert")
    public R insert( String typeName) {
        return goodTypeService.addType(typeName);
    }

    @ApiOperation(value = "修改")
    @PostMapping(value = "/update")
    public R update(@Validated(BraendType.class) @ApiParam GoodType goodType) {
        return goodTypeService.updateType(goodType);
    }

    @ApiOperation(value = "删除")
    @PostMapping(value = "/delete")
    public R<Boolean> delete(@Validated @ApiParam  Long typeId) {
        return goodTypeService.deleteType(typeId);
    }


}

